package com.micmac.customer.view.mediator
{
	import com.AppConst;
	import com.micmac.customer.events.CustomerArrayEvent;
	import com.micmac.customer.interfaces.ICustomerService;
	import com.micmac.customer.model.CorpModel;
	import com.micmac.customer.view.MarketView;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import org.robotlegs.utilities.modular.mvcs.ModuleMediator;

	public class MarketViewMediator extends ModuleMediator
	{
		[Inject]
		public var service:ICustomerService;
		[Inject]
		public var marketView:MarketView;
		[Inject]
		public var customerModel:CorpModel;
		
		override public function onRegister():void
		{
			eventMap.mapListener(eventDispatcher,CustomerArrayEvent.INDUSTRY_TYPE,onResultIndustryType);
			eventMap.mapListener(eventDispatcher,CustomerArrayEvent.INDUSTRY,onResultIndustry);
			addViewListener(MarketView.SHOW_INDUSTRY,getIndustry);
			getIndustryType();
		}
		
		private function onResultIndustryType(event:CustomerArrayEvent):void
		{
			var industryTypeList:ArrayCollection = event.listdata;
			marketView.industryTypeGrid.dataProvider = industryTypeList;
		}
		
		private function onResultIndustry(event:CustomerArrayEvent):void
		{
			var industryList:ArrayCollection = event.listdata;
			/*for (var i:int = 0;i<industryList.length;i++)
			{
				var obj:Object = new Object();
				obj.industryTypeList = customerModel.industryTypeResultList;
				industryList.addItemAt(obj,i);
			}*/
			marketView.industryGrid.dataProvider = industryList;
		}
		
		private function getIndustryType():void
		{
			service.getIndustryType();
		}
		
		private function getIndustry(event:Event):void
		{
			if(!marketView.industryGrid.dataProvider)
			service.getIndustry();
		}
	}
}